/**
 * 
 */
package com.jolestar.yayaweibotong.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jolestar.yayaweibotong.ServiceType;
import com.jolestar.yayaweibotong.dao.AccountDomain;
import com.jolestar.yayaweibotong.dao.UserDomain;

/**
 * @author jolestar@gmail.com
 * 
 */
public class DashboardAction extends AbstractAction {

	public DashboardAction() {
		super("dashboard");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.jolestar.yayaweibotong.controller.AbstractAction#doAction(javax.servlet
	 * .http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected String doAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		UserDomain user = (UserDomain) session.getAttribute("user");
		user.reloadAccount();
		List<AccountDomain> accounts = user.getAllAccounts();
		request.setAttribute("accounts", accounts);
		request.setAttribute("hasAccount", !accounts.isEmpty());
		request.setAttribute("user", user);
		request.setAttribute("services", ServiceType.getExternalServices());
		session.setAttribute("user", user);
		return "dashboard";
	}

	@Override
	public String getPath() {
		return "/" + this.getName();
	}

}
